<template>
	<view class="news">
		<block v-if="dataList.length!=0"> 
			<view class="news_list" v-for="item in dataList" :key="item.id">
				<view class="time">{{item.time}}</view>
				<view class="new_box" @click="jump(item)">
					<view class="title">{{item.title}}</view>
					<view class="subtitle">{{item.details}}</view>
				</view>
			</view>
<!-- 			<view>
				<view class="bottomLoading" v-if="lodingtype==0">加载中...</view>
				<view class="bottomLoading" v-if="lodingtype==1">已经到底啦</view>
			</view> -->
			<uni-load-more :status="moreStatus" v-if="dataList && dataList.length > 0"></uni-load-more>
			<view style="height: 40rpx;"></view>
		</block>

		<block v-else>
			<view class="no_info">
				<image src="/static/my/news_no.png" mode="widthFix"></image>
				<text>暂无通知消息</text>
			</view>
			
		</block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			  dataList:[], 
			  pageSize: 10, //每页记录数
			  pageNum: 1, //当前页码
			  listTotal: 0, //列表总数
			  lodingtype: 1, //加载状态（0：加载中  1：加载完成没有更多
			}
		},
		onLoad() {
			this.getEquityCardList()
		},
		methods: {
			jump(e){
				if(e.type == 3){
					uni.navigateTo({
						url: '/pages/my/news/notice-details?id='+e.id
					})
				}
				else if(e.issueStatus == 1){
					if(e.type == 1){
						uni.navigateTo({
							url: '/pages/pay/order-details?orderId='+e.businessId
						})
					}else{
						uni.navigateTo({
							url: '/pages/index/card-details/card-details?id='+e.businessId
						})
					}
				}else{
					uni.showToast({
						title:'本次活动已结束',
						icon:'none'
					})
				}

			},
			async getEquityCardList() {
				uni.showLoading({ title:'加载中' })
				this.moreStatus = 'loading'
				var _this = this
				let data = {
					pageSize: this.pageSize,
					pageNum: this.pageNum
				}
				try{
					const res = await this.$api.getEquityCardList(data);
					uni.hideLoading()
					this.listTotal = res.total
					res.rows = res.rows.map(el => {
						el.status = false
						return el;
					})
					if (this.pageNum >= Math.ceil(this.listTotal / this.pageSize)) {
						this.moreStatus = 'noMore'
					} else {
						this.moreStatus = 'more'
					}
					
					if (this.pageNum > 1) {
						this.dataList = this.dataList.concat(res.rows); //将数据拼接在一起
					} else {
						this.dataList = res.rows
					}
				}
				catch{
					uni.hideLoading()
				}finally{
					setTimeout(res=>{
						uni.hideLoading()
					},4000)
				}

				}
			},
		// 页面上拉触底事件的处理函数
		onReachBottom: function() {
			console.log("触底了", this.pageNum, Math.ceil(this.listTotal / this.pageSize), this.listTotal)
			if (this.pageNum >= Math.ceil(this.listTotal / this.pageSize)) {
				this.moreShop = 'noMore'
			} else {
				this.moreShop = 'more'
				this.pageNum++; //每触底一次 page + 1;
				this.getEquityCardList()
			}
		}
	}
</script>

<style scoped>
	page{
		background: #F8FBFF;
	}
	.news_list{
		width: 100%;
		padding-top: 42rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
	}
	.news_list .time{
		background: #CCCCCC;
		border-radius: 8rpx;
		padding: 4rpx 20rpx;
		color: #FFFFFF;
		font-size: 26rpx;
		margin-bottom: 20rpx;
	}
	.news_list .new_box{
		background: #FFFFFF;
		box-shadow: 4rpx 4rpx 12rpx #EEEEEE;
		border-radius: 16rpx;
		padding: 24rpx;
		width: 686rpx;
		box-sizing: border-box;
	}
	.new_box .title{
		color: #000000;
		margin-bottom: 10rpx;
		font-size: 34rpx;
	}
	.new_box .subtitle{
		font-size: 26rpx;
		color: #999999;
	}
	
</style>
